package org.laobai.properties;

import org.laobai.auth.utils.JwtUtils;
import org.laobai.auth.utils.RsaUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.security.PublicKey;

@Configuration
@ConfigurationProperties(prefix = "goods.jwt")
public class JWTProperties {

    private String pubKeyPath;// 公钥

    private Long expire;// token过期时间

    private PublicKey publicKey; // 公钥

    private static final Logger logger = LoggerFactory.getLogger(JWTProperties.class);
    @PostConstruct
    public void init(){
        try {
           this.publicKey =  RsaUtils.getPublicKey(pubKeyPath);
        } catch (Exception e) {
            logger.error("初始化公钥和私钥失败！", e);
            throw new RuntimeException();
        }
    }


    public String getPubKeyPath() {
        return pubKeyPath;
    }

    public void setPubKeyPath(String pubKeyPath) {
        this.pubKeyPath = pubKeyPath;
    }

    public Long getExpire() {
        return expire;
    }

    public void setExpire(Long expire) {
        this.expire = expire;
    }

    public PublicKey getPublicKey() {
        return publicKey;
    }

    public void setPublicKey(PublicKey publicKey) {
        this.publicKey = publicKey;
    }

}
